<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
    <head>
        <title>jQuery.Class Demo</title>
        <style type='text/css'>
            body {font-family: verdana}
            .tabs, .history_tabs {
                
                padding: 0px; margin: 20px 0 0 0;
            }
            li {
                float: left;
                padding: 10px;
                background-color: #F6F6F6;
                list-style: none;
                margin-left: 10px;
            }
            li a {
                color: #1C94C4;
                font-weight: bold;
                text-decoration: none;
            }
            li.active a {
                color: #F6A828;
                cursor: default;
            }
            .tab {
                border: solid 1px #F6A828;
            }
            /* clearfix from jQueryUI */
            .ui-helper-clearfix:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
            .ui-helper-clearfix { display: inline-block; }
            /* required comment for clearfix to work in Opera \*/
            * html .ui-helper-clearfix { height:1%; }
            .ui-helper-clearfix { display:block; }
            /* end clearfix */
        </style>
    </head>
    <body>
<p>jQuery.Class Demo shows a tabs controller extended to work with history.</p>
<div id="demo-html">
<h2>Basic Tabs</h2>
<ul id='tabs1' class='ui-helper-clearfix''>
    <li><a href='#tab1'>Tab 1</a></li>
    <li><a href='#tab2'>Tab 2</a></li>
    <li><a href='#tab3'>Tab 3</a></li>
</ul>
<div id='tab1' class='tab'>Tab 1 Content</div>
<div id='tab2' class='tab'>Tab 2 Content</div>
<div id='tab3' class='tab'>Tab 3 Content</div>
<h2>History Tabs</h2>
<ul id='tabs2' class='ui-helper-clearfix''>
    <li><a href='#tab4'>Tab 4</a></li>
    <li><a href='#tab5'>Tab 5</a></li>
    <li><a href='#tab6'>Tab 6</a></li>
</ul>
<div id='tab4' class='tab'>Tab 4 Content</div>
<div id='tab5' class='tab'>Tab 5 Content</div>
<div id='tab6' class='tab'>Tab 6 Content</div>
</div>
<script type='text/javascript'>DEMO_HTML = document.getElementById('demo-html').innerHTML</script>
<script type='text/javascript' src='../../steal/steal.js'></script>
<script type='text/javascript' id="demo-source">
steal('jquery/controller').then(function(){
$.Controller("Tabs",{
  init : function(){
    this.element.children("li:first").addClass('active')
    var tab = this.tab;
    this.element.children("li:gt(0)").each(function(){
      tab($(this)).hide()
    })
  },
  tab : function(li){
    return $(li.find("a").attr("href"))
  },
  "li click" : function(el, ev){
    ev.preventDefault();
    this.activate(el)
  },
  activate : function(el){
    this.tab(this.find('.active').removeClass('active')).hide()
    this.tab(el.addClass('active')).show();
  }
})

//inherit from tabs
Tabs("HistoryTabs",{

  // ignore clicks
  "li click" : function(){},
  
  // listen for history changes
  "{window} hashchange" : function(ev){
    var hash = window.location.hash;
    this.activate(hash === '' || hash === '#' ?
        this.element.find("li:first") : 
        this.element.find("a[href="+hash+"]").parent()
      )
  }
})

//adds the controller to the element
$("#tabs1").tabs();
$("#tabs2").history_tabs();
})
</script>
    </body>
</html>